package com.cardbaobao.cardbabyclient.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.buried.Google;
import com.cardbaobao.cardbabyclient.ui.activity.base.BaseActivity;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonViewPagerAdapter;
import com.cardbaobao.cardbabyclient.base.Constant;
import com.cardbaobao.cardbabyclient.ui.fragment.applyrecord.CreditApplyRecordFragment;
import com.cardbaobao.cardbabyclient.ui.fragment.applyrecord.LoansApplyRecordFragment;
import com.cardbaobao.cardbabyclient.buried.GoogleAnalyticsUtil;
import com.cardbaobao.cardbabyclient.widget.TitleBar;
import com.gyf.barlibrary.ImmersionBar;
import com.kekstudio.dachshundtablayout.DachshundTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Description: 我的申请记录
 * Created by FHW
 * on 2017/7/4
 */
public class ApplyRecordActivity extends BaseActivity {
    public static final String CURRENT_TAB_I = "currentTab";
    public static final int TAB_CREDIT_CARD = 0;//信用卡选项
    public static final int TAB_LOAN = 1;//贷款选项

    @BindView(R.id.tw_toolbar)
    TitleBar tw_toolbar;
    @BindView(R.id.vp_content)
    ViewPager vp_content;
    @BindView(R.id.dt_tab_layout)
    DachshundTabLayout dt_tab_layout;

    @Override
    protected void onResume() {
        super.onResume();
        GoogleAnalyticsUtil.setScreenName(Google.APPLY_RECORD);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        ImmersionBar.with(this).statusBarDarkFont(true,Constant.STATUS_BAR_FONT_ALPHA).init();
        tw_toolbar.setLeftViewOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        setViewpager();

    }

    private void setViewpager() {
        String[] titles = {
                "信用卡", "贷款"
        };

        List<Fragment> fragmentList = new ArrayList<>();
        CreditApplyRecordFragment creditApplyRecordFragment =
                CreditApplyRecordFragment.newInstance(CreditApplyRecordFragment.class, null);
        creditApplyRecordFragment.setBuriedInfo(mPrePageId);
        LoansApplyRecordFragment loansApplyRecordFragment =
                LoansApplyRecordFragment.newInstance(LoansApplyRecordFragment.class, null);
        loansApplyRecordFragment.setBuriedInfo(mPrePageId);
        fragmentList.add(creditApplyRecordFragment);
        fragmentList.add(loansApplyRecordFragment);

        CommonViewPagerAdapter infoPagerAdapter = new CommonViewPagerAdapter(getSupportFragmentManager()
                , titles, fragmentList);

        vp_content.setAdapter(infoPagerAdapter);
        dt_tab_layout.setupWithViewPager(vp_content);
        vp_content.setOffscreenPageLimit(fragmentList.size());

        vp_content.setCurrentItem(getIntent().getIntExtra(CURRENT_TAB_I, TAB_CREDIT_CARD));
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_apply_record;
    }
}
